package frame.options.simulation.results.virtualNetworks.graphical;

import java.awt.Color;
import java.awt.Paint;

import model.components.links.link.Link;
import model.components.links.link.VirtualLink;
import model.components.nodes.node.VirtualNode;
import model.components.nodes.node.PhysicalNode;

import org.apache.commons.collections15.Transformer;

public class VirtualLinkColorTransformer implements Transformer< Link, Paint >
{
	@Override
	public Paint transform( Link link )
	{	
		if( link.isSelected() )
			return Color.GREEN;
		
		int numLinksSubstrate = ( (VirtualLink) link ).getPhysicalLinksBandwidthsBackupFlags().size(); 
		
		if( numLinksSubstrate > 0 )
			return Color.YELLOW;
		
		PhysicalNode nodeSubstrateFirst = ( (VirtualNode) link.getFirstNode() ).getPhysicalNode();
		PhysicalNode nodeSubstrateSecond = ( (VirtualNode) link.getSecondNode() ).getPhysicalNode();
		
		if( nodeSubstrateFirst != null && nodeSubstrateSecond != null && !nodeSubstrateFirst.getNetworkName().equals( nodeSubstrateSecond.getNetworkName() ) )
			return Color.BLUE;
		
		return Color.BLACK;
	}
}
